package com.framework.controller;

import com.framework.exception.util.RespResult;
import com.framework.service.AgentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 功能描述: 用户授权
 *
 * @author ck
 * @date 2018/8/24 13:25
 */
@RestController
@Api(value="代理商授权模块",tags={"代理商授权模块"})
public class LoginController {

	@Autowired
	private AgentService agentService;

	/**
	 * 功能描述: 登录操作
	 */
	@PostMapping("login")
	@ApiOperation(value = "登录",notes = "APP登录接口",httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name="phone",value="手机号码",dataType="string", paramType = "query" ,required = true),
			@ApiImplicitParam(name="password",value="密码,需要AES加密传输",dataType="string", paramType = "query",required = true),
			@ApiImplicitParam(name="deptId",value="渠道id,固定值",dataType="Long", paramType = "query",required = true)
	})
	public RespResult login(String phone,String password,Long deptId) {
		// 用户登录
		Map<String,Object> map = agentService.login(phone,password,deptId);
		return RespResult.ok(map);
	}

	/**
	 * 退出登录
	 */
	@PostMapping("user/outLogin")
	@ApiOperation("退出登录")
	public RespResult outLogin(String token) {
		agentService.outLogin(token);
		return RespResult.ok();
	}
}
